unit Unit7;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, unit1, unit9, unit2, unit8, unit10;

type
  TForm7 = class(TForm)
    RadioGroup1: TRadioGroup;
    GroupBox1: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    GroupBox2: TGroupBox;
    ComboBox1: TComboBox;
    GroupBox3: TGroupBox;
    ComboBox2: TComboBox;
    ComboBox3: TComboBox;
    procedure Button2Click(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure ComboBox1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ComboBox2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type SubFac=record
 SF_uuid:string[50];
 NameSF:string[7];
 FacultyUUID:string[50];
end;

type Group=record
  GrUUID:string[50];
  FakUUID:string[50];
  GrName:string[15];
  Spec:string[20];
end;

var
  Form7: TForm7;
  butN:byte;
  SF:array of SubFac;
  GR:array of Group;

implementation

{$R *.dfm}

procedure TForm7.Button2Click(Sender: TObject);
begin
Form7.Close;
end;

procedure TForm7.RadioGroup1Click(Sender: TObject);
var
  i:Byte;
begin
if (ComboBox2.Text<>'') and (ComboBox1.Text<>'') then
begin
   ComboBox3.Clear;
   ComboBox3.ItemIndex:=0;
   DataModule2.qryGroups.SQL.Clear;
   DataModule2.qryGroups.SQL.Text:='SELECT * FROM Groups WHERE SubFaculty_UUID='#39+SF[ComboBox2.ItemIndex].SF_uuid+#39' AND Semester='#39+IntTostr((ComboBox1.ItemIndex+1)*2-1+RadioGroup1.ItemIndex)+#39'';
   DataModule2.qryGroups.Open;
    if DataModule2.SourceGroups.DataSet.RecordCount<>0 then
     begin
       DataModule2.SourceGroups.DataSet.First;
       SetLength(GR,0);
       SetLength(GR,DataModule2.SourceGroups.DataSet.RecordCount);
        for i:=0 to DataModule2.SourceGroups.DataSet.RecordCount-1 do
         begin
           ComboBox3.Items.Add(DataModule2.SourceGroups.DataSet.FieldByName('GroupName').AsString);
           GR[i].GrUUID:=Datamodule2.SourceGroups.DataSet.FieldByName('Group_UUID').AsString;
           GR[i].GrName:=DataModule2.SourceGroups.DataSet.FieldByName('GroupName').AsString;
           GR[i].FakUUID:=DataModule2.SourceGroups.DataSet.FieldByName('SubFaculty_UUID').AsString;
           GR[i].Spec:=DataModule2.SourceGroups.DataSet.FieldByName('Speciality').AsString;
           DataModule2.SourceGroups.DataSet.Next;
         end;
        end;
      DataModule2.qryGroups.Close;
 end;
end;

procedure TForm7.Button1Click(Sender: TObject);
var
i,j:integer;
begin
 Application.CreateForm(TForm9, Form9);
 if ComboBox3.Text<>'' then
 begin

 unit9.idg9:=Gr[ComboBox3.ItemIndex].GrUUID;
 unit9.spec9:=GR[ComboBox3.itemIndex].Spec;
 unit9.fakid9:=GR[ComboBox3.ItemIndex].FakUUID;
 unit9.sem9:=IntTostr((ComboBox1.ItemIndex+1)*2-1+RadioGroup1.ItemIndex);

 Unit9.Form9.Label2.Caption:=ComboBox3.Text;
 Unit2.DataModule2.ADOQuery2.Close;
 Form7.Close;
  for i:=2 to 28 do
  for j:=1 to 6 do
  begin
  unit9.Form9.ZColorStringGrid1.Cells[i,j]:='';
  unit9.Form9.ZColorStringGrid2.Cells[i,j]:='';
  end;
 Unit9.Form9.Show;
 end;
end;

procedure TForm7.ComboBox1Click(Sender: TObject);
var
  i:Byte;
begin
if ComboBox2.Text<>'' then
begin
   ComboBox3.Clear;
   ComboBox3.ItemIndex:=0;
   DataModule2.qryGroups.SQL.Clear;
   DataModule2.qryGroups.SQL.Text:='SELECT * FROM Groups WHERE SubFaculty_UUID='#39+SF[ComboBox2.ItemIndex].SF_uuid+#39' AND Semester='#39+IntTostr((ComboBox1.ItemIndex+1)*2-1+RadioGroup1.ItemIndex)+#39'';
   DataModule2.qryGroups.Open;
    if DataModule2.SourceGroups.DataSet.RecordCount<>0 then
     begin
       DataModule2.SourceGroups.DataSet.First;
       SetLength(GR,0);
       SetLength(GR,DataModule2.SourceGroups.DataSet.RecordCount);
        for i:=0 to DataModule2.SourceGroups.DataSet.RecordCount-1 do
         begin
           ComboBox3.Items.Add(DataModule2.SourceGroups.DataSet.FieldByName('GroupName').AsString);
           GR[i].GrUUID:=Datamodule2.SourceGroups.DataSet.FieldByName('Group_UUID').AsString;
           GR[i].GrName:=DataModule2.SourceGroups.DataSet.FieldByName('GroupName').AsString;
           GR[i].FakUUID:=DataModule2.SourceGroups.DataSet.FieldByName('SubFaculty_UUID').AsString;
           GR[i].Spec:=DataModule2.SourceGroups.DataSet.FieldByName('Speciality').AsString;
           DataModule2.SourceGroups.DataSet.Next;
         end;
        end;
      DataModule2.qryGroups.Close;
 end;
end;

procedure TForm7.FormCreate(Sender: TObject);
var
  i:Byte;
begin
ComboBox1.Items.Add('1');
ComboBox1.Items.Add('2');
ComboBox1.Items.Add('3');
ComboBox1.Items.Add('4');
ComboBox1.Items.Add('5');
ComboBox1.Items.Add('6');
ComboBox1.ItemIndex:=0;
ComboBox2.Clear;
ComboBox3.Clear;
DataModule2.qrySubFac.SQL.Clear;
DataModule2.qrySubFac.SQL.Text:='SELECT * FROM SubFaculty';
DataModule2.qrySubFac.Open;
if DataModule2.SourseSubFac.DataSet.RecordCount<>0 then
  begin
   DataModule2.SourseSubFac.DataSet.First;
   SetLength(SF,0);
   SetLength(SF,DataModule2.SourseSubFac.DataSet.RecordCount);
    for i:=0 to DataModule2.SourseSubFac.DataSet.RecordCount-1 do
    begin
     SF[i].NameSF:=DataModule2.SourseSubFac.DataSet.FieldByName('NameShort').AsString;
     SF[i].SF_uuid:=DataModule2.SourseSubFac.DataSet.FieldByName('SubFaculty_UUID').AsString;
     SF[i].FacultyUUID:=DataModule2.SourseSubFac.DataSet.FieldByName('Faculty_UUID').AsString;
     ComboBox2.Items.Add(DataModule2.SourseSubFac.DataSet.FieldByName('NameShort').AsString);
     DataModule2.SourseSubFac.DataSet.Next;
    end;

   ComboBox3.ItemIndex:=0;
   ComboBox2.ItemIndex:=0;
   DataModule2.qrySubFac.Close;
   DataModule2.qryGroups.SQL.Clear;
   DataModule2.qryGroups.SQL.Text:='SELECT * FROM Groups WHERE SubFaculty_UUID='#39+SF[ComboBox2.ItemIndex].SF_uuid+#39' AND Semester='#39+IntTostr((ComboBox1.ItemIndex+1)*2-1+RadioGroup1.ItemIndex)+#39'';
   DataModule2.qryGroups.Open;
    if DataModule2.SourceGroups.DataSet.RecordCount<>0 then
     begin
       ComboBox3.Clear;
       DataModule2.SourceGroups.DataSet.First;
       SetLength(GR,0);
       SetLength(GR,DataModule2.SourceGroups.DataSet.RecordCount);
        for i:=0 to DataModule2.SourceGroups.DataSet.RecordCount-1 do
         begin
           ComboBox3.Items.Add(DataModule2.SourceGroups.DataSet.FieldByName('GroupName').AsString);
           GR[i].GrName:=DataModule2.SourceGroups.DataSet.FieldByName('GroupName').AsString;
           GR[i].FakUUID:=DataModule2.SourceGroups.DataSet.FieldByName('SubFaculty_UUID').AsString;
           GR[i].Spec:=DataModule2.SourceGroups.DataSet.FieldByName('Speciality').AsString;
           DataModule2.SourceGroups.DataSet.Next;
         end;
        end;
      DataModule2.qryGroups.Close;
     end;

  
end;

procedure TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;

procedure TForm7.ComboBox2Click(Sender: TObject);
var
  i:Byte;
begin
   ComboBox3.Clear;
   ComboBox3.ItemIndex:=0;
   DataModule2.qryGroups.SQL.Clear;
   DataModule2.qryGroups.SQL.Text:='SELECT * FROM Groups WHERE SubFaculty_UUID='#39+SF[ComboBox2.ItemIndex].SF_uuid+#39' AND Semester='#39+IntTostr((ComboBox1.ItemIndex+1)*2-1+RadioGroup1.ItemIndex)+#39'';
   DataModule2.qryGroups.Open;
    if DataModule2.SourceGroups.DataSet.RecordCount<>0 then
     begin
       DataModule2.SourceGroups.DataSet.First;
       SetLength(GR,0);
       SetLength(GR,DataModule2.SourceGroups.DataSet.RecordCount);
        for i:=0 to DataModule2.SourceGroups.DataSet.RecordCount-1 do
         begin
           ComboBox3.Items.Add(DataModule2.SourceGroups.DataSet.FieldByName('GroupName').AsString);
           GR[i].GrUUID:=Datamodule2.SourceGroups.DataSet.FieldByName('Group_UUID').AsString;
           GR[i].GrName:=DataModule2.SourceGroups.DataSet.FieldByName('GroupName').AsString;
           GR[i].FakUUID:=DataModule2.SourceGroups.DataSet.FieldByName('SubFaculty_UUID').AsString;
           GR[i].Spec:=DataModule2.SourceGroups.DataSet.FieldByName('Speciality').AsString;
           DataModule2.SourceGroups.DataSet.Next;
         end;
        end;
      DataModule2.qryGroups.Close;
end;

end.
